//
//  LoginViewController.m
//  IntimateGift
//
//  Created by zh on 14/12/22.
//  Copyright (c) 2014年 蔡宏业. All rights reserved.
//

#import "LoginViewController.h"
#import "UIColor+AddColor.h"
#import "WeiboViewController.h"
//#import <ShareSDK/ShareSDK.h>
#import "WBSDKBasicButton.h"
#import "WeiboSDK.h"
#import "WBSDKRelationshipButton.h"


@interface LoginViewController ()

//{
//    WBSDKRelationshipButtonState *relationshipButton;
//    WBSDKCommentButton *commentButton;
//    
//    
//}


@end

@implementation LoginViewController


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center addObserver:self selector:@selector(receiveNotifica:) name:@"tamenlaile" object:nil];
    }
    return self;
}

- (void)receiveNotifica:(NSNotification *)center
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
//    [self.view addSubview:view];
//    [view setBackgroundColor:[UIColor ownColor]];
//    
//    // 取消按钮
//    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    [view addSubview:cancelButton];
//    cancelButton.frame = CGRectMake(5, 20, 60, 40);
//    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
//    cancelButton.tintColor = [UIColor whiteColor];
//    [cancelButton addTarget:self action:@selector(cancelButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//    [view release];
    // 登陆图片
    UIImageView *loginImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 2 - self.view.bounds.size.width * 0.13, self.view.bounds.size.height - self.view.bounds.size.height * 0.76, self.view.bounds.size.width * 0.28, self.view.bounds.size.height * 0.15)];
    [self.view addSubview:loginImageView];
//    loginImageView.backgroundColor = [UIColor redColor];
    loginImageView.image = [UIImage imageNamed:@"iconfont-yonghu.png"];
    [loginImageView release];
    
    UILabel *loginLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 2 - self.view.bounds.size.width * 0.13, self.view.bounds.size.height - self.view.bounds.size.height * 0.6, self.view.bounds.size.width * 0.28, self.view.bounds.size.height * 0.05)];
    [self.view addSubview:loginLabel];
    loginLabel.text = @"未登录";
//    loginLabel.backgroundColor = [UIColor redColor];
    loginLabel.textAlignment = 1;
    [loginLabel release];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 2 - self.view.bounds.size.width * 0.24, self.view.bounds.size.height - self.view.bounds.size.height * 0.56, self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.05)];
    [self.view addSubview:label];
    label.textAlignment = 1;
    label.text = @"登陆以享受更多功能";
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:14];
    [label release];
    
    // 微博登陆
    UIView *weiboView = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width * 0.1, self.view.bounds.size.height - self.view.bounds.size.height * 0.4, self.view.bounds.size.width * 0.8, self.view.bounds.size.height * 0.085)];
    [self.view addSubview:weiboView];
    weiboView.backgroundColor = [UIColor ownColor];
    
    UIImageView *weiboImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, weiboView.bounds.size.width * 0.15, weiboView.bounds.size.height * 0.7)];
//    weiboImageView.backgroundColor = [UIColor cyanColor];
    [weiboView addSubview:weiboImageView];
    weiboImageView.image = [UIImage imageNamed:@"iconfont-weibo.png"];
    [weiboImageView release];
    
    UILabel *weiboLabel = [[UILabel alloc] initWithFrame:CGRectMake(weiboView.bounds.size.width * 0.3, 10, weiboView.bounds.size.width * 0.5, weiboView.bounds.size.height * 0.7)];
    [weiboView addSubview:weiboLabel];
    weiboLabel.textColor = [UIColor whiteColor];
    weiboLabel.text = @"使用微博登陆";
    weiboLabel.textAlignment = 1;
    
    UIButton *weiboButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:weiboButton];
    weiboButton.frame = CGRectMake(self.view.bounds.size.width * 0.1, self.view.bounds.size.height - self.view.bounds.size.height * 0.4, self.view.bounds.size.width * 0.8, self.view.bounds.size.height * 0.085);
//    weiboButton.backgroundColor = [UIColor redColor];
    [weiboButton addTarget:self action:@selector(weiboButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [weiboLabel release];
    [weiboView release];
    
    
    
    // Do any additional setup after loading the view.
}

- (void)weiboButtonClicked:(UIButton *)button
{
        
    
//    WeiboViewController *weiboVC = [[WeiboViewController alloc] init];
//    [self presentViewController:weiboVC animated:YES completion:^{
//        
//    }];
//    [weiboVC release];
    
    WBAuthorizeRequest *request = [WBAuthorizeRequest request];
    request.redirectURI = @"http://open.weibo.com";
    request.scope = @"all";
    request.userInfo = @{@"SSO_From": @"LoginViewController",
                         @"Other_Info_1": [NSNumber numberWithInt:123],
                         @"Other_Info_2": @[@"obj1", @"obj2"],
                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
    
    [WeiboSDK sendRequest:request];
    
    
    
}

- (void)cancelButtonClicked:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
